<?php

namespace App\Admin\Controllers;

use Illuminate\Http\Request;
use App\AdminRole;
use App\AdminUser;
use App\AdminPermission;

class PermissionController extends Controller
{
	//权限列表页
    public function index()
    {
        $permissions = AdminPermission::orderBy('id', 'asc')->paginate(10);
        return view('/admin/permission/index', compact('permissions'));
    }
    
    //创建权限页面
    public function create()
    {
        return view('/admin/permission/add');
    }

    //权限列表页
    public function store()
    {
        //验证
        $this->validate(request(),[
            'name' => 'required|min:3|unique:admin_roles,name',
            'description' => 'required'
        ]);
        //逻辑
        AdminPermission::create(request(['name', 'description']));

        //渲染
        return redirect('/admin/permissions');
    }

}
